package com.jinyi.wwdeng.ui.main.impl

import com.jinyi.base.mvp.BaseModel
import com.jinyi.base.network.IRequestCallback
import com.jinyi.base.network.NetworkUtils
import com.jinyi.wwdeng.network.ApiService
import com.jinyi.wwdeng.network.HttpBaseParams.addCommonParams
import com.jinyi.wwdeng.ui.main.contract.CreditRepaymentContract
import org.json.JSONObject

/**
 * JinYiTest
 * @Author wwdeng
 * @CreateTime: 2024/4/28 16:19
 * @Annotation：Model层  接口实现类
 */
class CreditRepaymentModelImpl(iCallback: CreditRepaymentContract.Presenter): BaseModel<CreditRepaymentContract.Presenter>(iCallback),CreditRepaymentContract.Model {
    /**
     * 加载还款信息
     */
    override fun loadRepaymentDataRequest() {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_CREDIT_REPAYMENT_INFO)
        }
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onRepaymentDataSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }

    /**
     * 获取还款url
     */
    override fun loadRepaymentUrlRequest() {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_CREDIT_REPAYMENT_URL)
        }
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onRepaymentUrlSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }
}